﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Babylon.Animations
{
    public abstract class DurationBasedAnimation : AnimationBase
    {
        public float Duration { get; set; }

        public float NormalizedAnimationTime
        {
            get { 
                var normalizedBase = base.AnimationEllapsedTime/Duration;
                if (normalizedBase <= 1)
                    return normalizedBase;
                var step = (int) Math.Floor(normalizedBase);
                normalizedBase -= step;
                if(AutoReverse)
                {
                    if (!RepeatForever && step > 1)
                        return 1;
                    var mod2 = step%2;
                    if(mod2 == 1)
                        normalizedBase = 1 - normalizedBase;
                    return normalizedBase;
                }

                if (!RepeatForever)
                    return 1;
                return normalizedBase;
            }
        }
    }
}
